home *** CD-ROM | disk | FTP | other *** search
- #include "bbs.h"
-
- /* string_in_file.c */
-
- /* a given filename to a list of strings we want to check for. *
- * If the string exists in the list, return TRUE, otherwise *
- * return FALSE (even if the file can't be opened). *
- */
-
- /* fname is name of file */
- /* str = ptr to filename of file to upload */
- /* use flag for wild */
-
- #define USE_WILD_ASTER 0x01
- #define USE_WILD_ALL 0x02
- #define USE_WILD_AMY 0x04 /* use #? */
-
- int String_In_File(char *fname, char *str, int flag)
- {
- FILE *fp;
- char buff[255];
- register char *s, *p, *tmpstr;
-
- if(!(fp = fopen(fname,"r"))) { /* can't find our file */
- return(FALSE); /* can't open file so nope string doesn't exist */
- }
- while(fgets(&buff[0],255,fp)!=0) {
- buff[strlen(buff)-1] = '\0'; /* remove newline (dunno why) */
- s = &buff[0];
-
- /* skip beginning spaces */
- while(*s == ' ') s++;
- p = s;
-
- if(flag) { /* use '*' as wild card */
- while(*p && *p!= '*') p++;
- if(*p == '*') { /* found a wild card, everything after this can not be sent up */
- p++; /* move past aster */
- tmpstr = str+strlen(str)-1; /* goto last char in string */
- tmpstr -= strlen(p) -1; /* backup p chars - 1 */
- if(stricmp(tmpstr,p) == 0) {
- fclose(fp);
- return(TRUE); /* found text in list */
- }
- }
-
- }
-
- // sprintf(WORKB,"looking for: [%s] in [%s]\n",str,s);
- // ErrorLog(WORKB);
- if(strnicmp(s,str,strlen(str)) == 0) {
- fclose(fp);
- return(TRUE); /* found text in list */
- }
-
- }
- fclose(fp);
- return(FALSE); /* didn't find text in list */
- }
-